package com.wolfeyes.common.utils.framework.spring;

import com.wolfeyes.common.utils.character.StringUtils;

/**
 * @description MQ领域工具类
 * @author yanyljava
 *
 */
public class RabbitUtil {

    public static final String DEFAULT_QUEUE_NAME = "default.queue";
    public static final String DEFAULT_EXCHANGE_NAME = "default.exchange";
    public static final String DEFAULT_ROUTING_KEY_NAME = "default.routing.key";
    
    public static String getBeanName(Class<?> entityClazz) {
    	
		// 获取源代码中给出的底层类名的简称SimpleName
		String simpleName = entityClazz.getSimpleName();
		
		// bean名称（首字母小写转换toLowerCase）
		String beanName = StringUtils.uncapitalize(simpleName);
		
		return beanName;
    }
    
    public static String getDefaultQueueName(Class<?> entityClazz) {
		
    	String beanName = RabbitUtil.getBeanName(entityClazz);
    	
    	String entityQueueName = RabbitUtil.DEFAULT_QUEUE_NAME.replace("default", beanName);
    	
    	return entityQueueName;
    	
	}
    
    public static String getDefaultDirectExchangeName(Class<?> entityClazz) {
    	
		String beanName = RabbitUtil.getBeanName(entityClazz);
		
    	String entityDirectExchangeName = RabbitUtil.DEFAULT_EXCHANGE_NAME.replace("default", beanName);
    	
    	return entityDirectExchangeName;
	}
    
    public static String getDefaultRoutingKeyName(Class<?> entityClazz) {
		
    	String beanName = RabbitUtil.getBeanName(entityClazz);
    	
    	String entityRoutingKeyName = RabbitUtil.DEFAULT_ROUTING_KEY_NAME.replace("default", beanName);
    	
    	return entityRoutingKeyName;
    	
	}
    
}

